import { AuthStore } from "@/stores/modules/auth";
import { computed } from "vue";
import { useRoute } from "vue-router";

/**
 * @description: 页面按钮权限
 * @return {*}
 */
export const useAuthButtons = () => {
	const route = useRoute();
	const authStore = AuthStore();
	// 根据返回的路由别名， 进行页面按钮的权限配置
	/**
	 * 模拟后端返回格式
	 * {
	 * 		useProTable: ["add", "edit"，"delete"],
	 * 		treeProTable: ["add", "edit","delete"]
	 * }
	 */
	const authButtons = authStore.authButtonListGet[route.name as string] || [];

	const BUTTONS = computed(() => {
		let currentPageAuthButton: { [key: string]: boolean } = {};
		authButtons.forEach(item => (currentPageAuthButton[item] = true));
		return currentPageAuthButton;
	});

	return {
		BUTTONS
	};
};
